<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head th:include="include/includeTablebase"></head>
<body>
<div class="panel-body" style="padding-bottom:0px;">
    <div class="panel panel-default">
        <div class="panel-heading">查询条件</div>
        <div class="panel-body">
            <form class="form-inline" role="form" style="float: left; width: 100%;" method="post" id="queryRole">
                <div class="form-group">
                    <label for="name">权限代码:</label>
                    <input type="text" class="form-control" name="name" id="name"  placeholder="请输入权限代码" />
                </div>
                <div class="form-group">
                    <label for="nickName">权限名称:</label>
                    <input type="text" class="form-control" name="nickName" id="nickName"  placeholder="请输入权限名称" />
                </div>
                <div class="form-group">
                    <button type="button" id="queryBtn" onclick="doQuery();" class="btn btn-primary">查询</button>
                </div>
            </form>
        </div>
    </div>
    <table id="role-table" style="margin-top: -50px;">
    </table>
</div>
<script th:inline="javascript">

    // 获取当前窗口的宽度
    var winWidth = $(window.parent.document).find("#wrapper").width();

    $(function() {
        setTimeout('initTable()',100);
        $('#role-table').bootstrapTable('hideColumn', 'id');
    });

    function doQuery(){
        // 移除遮罩层的属性否则会导致在移动端无法显示滚动条
        $('body').removeClass("modal-open");
        $('#role-table').bootstrapTable('refresh');    //刷新表格
    }

    function initTable(){
        $.fn.bTableUtil({
            id:"role-table",
            url:"role/list",
            formId :"queryRole",
            sortName : 'id',
            sortOrder : 'desc',
            toolbars:[
                {
                    text: '添加',
                    iconCls: 'glyphicon glyphicon-plus',
                    code : 'add_role',
                    verify : false,
                    handler: function () {
                        window.Ewin.dialog({title:"添加",url:"/role/addPage",width:winWidth<=415?winWidth-20:400,height:510})
                    }
                },
                {
                    text: '修改',
                    iconCls: 'glyphicon glyphicon-pencil',
                    code : 'edit_role',
                    verify : false,
                    handler: function () {
                        var rows = $('#role-table').bootstrapTable('getSelections');
                        if(rows.length==0||rows.length>1){
                            window.Ewin.alert({message:'请选择一条需要修改的数据!'});
                            return false;
                        }
                        window.Ewin.dialog({title:"修改",url:"/role/updatePage?id="+rows[0].id,width:winWidth<=415?winWidth-20:400,height:510});
                    }
                },
                {
                    text: '删除',
                    iconCls: 'glyphicon glyphicon-remove',
                    code : 'remove_role',
                    verify : false,
                    handler: function () {
                        var rows = $('#role-table').bootstrapTable('getSelections');
                        if(rows.length==0){
                            window.Ewin.alert({message:'请选择一条需要删除的数据!'});
                            return false;
                        }
                        window.Ewin.confirm({title:'提示',message:'是否要删除您所选择的记录？',width:500}).on(function (e) {
                            if (e) {
                                $.post("/role/removeBath",{json:JSON.stringify(rows)},function(e){
                                    if(e.result){
                                        window.Ewin.alert({message:e.msg});
                                        doQuery();
                                    }else{
                                        window.Ewin.alert({message:e.msg});
                                    }
                                });
                            }
                        });
                    }
                }
            ],
            columns: [
                {
                    checkbox: true
                },
                {
                    field: '',
                    title: '序号',
                    formatter: function (value, row, index) {
                        return index+1;
                    }
                },
                {
                    field : 'id',
                    title : '权限流水',
                    align : 'center',
                    valign : 'middle',
                    visible: false,
                    sortable : true
                },
                {
                    field : 'name',
                    title : '权限代码',
                    align : 'center',
                    valign : 'middle',
                    sortable : true
                },
                {
                    field : 'nickName',
                    title : '权限名称',
                    align : 'center',
                    valign : 'middle',
                    sortable : true
                }]
        });
    }
</script>
</body>
</html>